
// export type DebounceFunc = (...args: any[]) => any

// /**
//  * 防抖
//  * @example
//  * debounce(()=>{})
//  */
// export const debounce = function (func: DebounceFunc, wait?: number) {
//   wait = wait || 300;
//   var timeout: NodeJS.Timeout;
//   return function(...args: any[]) {
//     clearTimeout(timeout)
//     timeout = setTimeout(() => func(...args), wait)
//   }
// }

/**
 * 防抖
 * @example
 * debounce(()=>{})
 */
export const debounce = function<T extends (...args: any) => any>(func: T, wait?: number): (...args: Parameters<T>) => void {
  wait = wait || 300;
  var timeout: NodeJS.Timeout;
  return function(...args: any[]) {
    clearTimeout(timeout)
    timeout = setTimeout(() => func(...args), wait)
  }
}